#include <iostream>
#include <cstdio>
#include <algorithm>

const int N = 305;

int n;
int a[N], f[N][N][N];

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);

	std::freopen("build.in", "r", stdin);
	std::freopen("build.out" ,"w", stdout);

	std::cin >> n;
	for(int i = 1; i <= n; ++i) std::cin >> a[i];
	for(int len = 1; len <= n; ++len) {
		for(int i = 1; i <= n; ++i) {
			int j = i + len - 1;
			if(j > n) break;
			for(int k = 0; k < n; ++k) {
				f[i][j][k] = std::max(f[i][j][k], f[i+1][j][k] + (a[i] == k + (j - i + 1)));
				f[i][j][k] = std::max(f[i][j][k], f[i][j-1][k] + (a[j] == k + (j - i + 1)));
				f[i][j][k] = std::max(f[i][j][k], f[i+1][j][k+1] + (a[i] == k + 1));
				f[i][j][k] = std::max(f[i][j][k], f[i][j-1][k+1] + (a[j] == k + 1));
			}
		}
	}
	std::cout << n - f[1][n][0] << "\n";

	return 0;
}
